//package aimis.config.db;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.DependsOn;
//import org.springframework.context.annotation.Profile;
//import aimis.domain.Department;
//import aimis.repo.DepartmentRepo;
//
//@Profile(value = { "test", "dev", "local"})
//@Configuration
//public class DepartmentInitConfig {
//    private Logger LOGGER = LoggerFactory.getLogger(DepartmentInitConfig.class);
//    @Autowired
//    private DepartmentRepo departmentRepo;
//
//    @Bean
//    @DependsOn("authorityInit")
//    public void departmentInit() {
//        LOGGER.info("初始化部门开始...");
//        try {
//            analysts();
//        }catch (Exception e)
//        {
//            e.printStackTrace();
//        }
//        LOGGER.info("初始化部门结束");
//    }
//
//    private void analysts() {
//        var secureCenter = newDepartment("安全中心",null);
//
//        var cqu = newDepartment("重庆大学",null);
////        var department = newDepartment("分析师",cqu);
////        newDepartment("一线分析师",department);
////        newDepartment("二线分析师",department);
////        newDepartment("三线分析师",department);
//        var pk = newDepartment("北京大学",null);
//
////        department = newDepartment("分析师",pk);
////        newDepartment("一线分析师",department);
////        newDepartment("二线分析师",department);
////        newDepartment("三线分析师",department);
//    }
//
//    private void interactionManager() {
//        var cqu= departmentRepo.findByNameAndParent("重庆大学",null);
//        newDepartment("交互经理",cqu);
//        var pk= departmentRepo.findByNameAndParent("北京大学",null);
//        newDepartment("交互经理",pk);
//    }
//
//
//    private Department newDepartment(String name, Department parent) {
//        try {
//            var department=departmentRepo.findByNameAndParent(name,parent);
//            if(department !=null)
//                return department; //已经存在则不添加
//            department = new Department();
//            department.setName(name);
//            department.setParent(parent);
//            department = departmentRepo.save(department);
//            if(department.getParent()==null)
//            {
//                department.setRoot(department);
//                department = departmentRepo.save(department);
//            }else{
//                department.setRoot(department.getParent().getRoot());
//                department = departmentRepo.save(department);
//            }
//            return department;
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return null;
//    }
//}
